import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import { IsNotEmpty, IsOptional, Matches } from 'class-validator';

export class RegisterDto {
  //用户名
  @ApiProperty({ description: '用户名', example: 'admin', required: true })
  @IsNotEmpty({ message: '用户名不能为空' })
  username: string;

  //密码
  @ApiProperty({ description: '密码', example: 'abc123456', required: true })
  @IsNotEmpty({ message: '密码不能为空' })
  //密码必须包含字母和数字，且长度不小于8位
  @Matches(/^(?=.*[A-Za-z])(?=.*\d)[A-Za-z\d]{8,}$/, {
    message: '密码必须包含字母和数字，且长度不小于8位',
  })
  password: string;

  //昵称
  @ApiPropertyOptional({
    description: '昵称',
    example: 'admin',
  })
  @IsOptional()
  @IsNotEmpty({ message: '昵称不能为空' })
  nickname?: string;

  //头像
  @ApiPropertyOptional({
    description: '头像',
    example: 'http://localhost:3000/uploads/avatar/1.jpg',
  })
  @IsOptional()
  @IsNotEmpty({ message: '头像不能为空' })
  avatar_url?: string;

  //邮箱
  @ApiPropertyOptional({
    description: '邮箱',
    example: '123@admin.com',
    default: 'example@example.com',
  })
  @IsOptional()
  email?: string;

  //角色
  @ApiPropertyOptional({
    description: '角色',
    example: 'admin',
  })
  @IsOptional()
  role?: 'admin' | 'user';
}
